﻿var resUrl=document.getElementById('sername').value;
var res_Url=document.getElementById('resUrl').value;
var serhost=document.getElementById('serhost').value;
var version=document.getElementById('version').value;

var app=angular.module("app",['ngRoute']);
app.run(function($log, $rootScope, $http, $templateCache){
		
		//每个页面的顶部栏参数
		$rootScope.page={
			topOpen:false,
			title:'',
			leftNav:'',
			rightNav:''
		}
		
		$rootScope.callSuccessHttp = function() {
				$rootScope.uiObj.loading = false;	
				$rootScope.uiObj.isactive = 'active';
				$rootScope.uiObj.layerloadingCtrl=false;
				layer.closeAll();
			
		}
		
		
		$rootScope.uiObj={
			    	defaultHeadImg:document.getElementById('defaultHeadImg').value,
			    	pageloadingCtrl:true,
			    	layerloadingCtrl:false,
			    	uiloadingCtrl:false,
			    	loading:true,
			    	isactive:''
		  }
		
		 $rootScope.$on('$routeChangeStart',function(evt,next,current){
		 		var currentPage=next.$$route.controller;
        		$rootScope.uiObj.loading = false;
        		$rootScope.uiObj.layerloadingCtrl=true;
            	$rootScope.uiObj.isactive = '';
            	var isbind=document.getElementById('isbind').value;
            	
            	if(isbind!="1"&&currentPage!="loginCtrl")
            	{
            		location.href="#/login"
            	}
            	else if(isbind=="1"&&currentPage=="loginCtrl")
            	{
            		location.href="#/"
            	}
            	
		 })
		 
		 $rootScope.$on('$routeChangeSuccess',function(evt,current,previous){
//		 	var pageNameCtrl=current.$$route.controller
//		 	switch(pageNameCtrl){
//		 		case 'refereeInfoCtrl':
//		 		
//		 		break;
//		 	}
			wx_share.init(shareData);
		 })
		  //全局方法和变量
          $rootScope.initSwiper = function (_class) {

				$rootScope.mySwiper = new Swiper(_class, {
					pagination : '.swiper-pagination'
				});
				
          	 	console.log($rootScope.mySwiper);

          }
          $rootScope.updateSwiper=function(){
          			$rootScope.mySwiper.update();
          }
          
          $rootScope.loadLoyer=function(){
          	layer.open({
            		content:'<div class="spinner">'
            				+'<div class="spinner-container container1">'
            					+'<div class="circle1"></div>'
            					+'<div class="circle2"></div>'
            					+'<div class="circle3"></div>'
            					+'<div class="circle4"></div>'
            				+'</div>'
            				+'<div class="spinner-container container2">'
            					+'<div class="circle1"></div>'
            					+'<div class="circle2"></div>'
            					+'<div class="circle3"></div>'
            					+'<div class="circle4"></div>'
            				+'</div>'
            				+'<div class="spinner-container container3">'
            					+'<div class="circle1"></div>'
            					+'<div class="circle2"></div>'
            					+'<div class="circle3"></div>'
            					+'<div class="circle4"></div>'
            				+'</div>',
            		style:'text-align:center;',
            		shadeClose: false
            })
          }
  });
app.config(function($routeProvider,$httpProvider){
    $routeProvider.when("/login",{
        templateUrl: resUrl+'wx_api/Module/settlement/views/login.html'+version,
        controller: 'loginCtrl'
    }).when("/accountList/:type",{
        templateUrl: resUrl+'wx_api/Module/settlement/views/accountList.html'+version,
        controller: 'accountListCtrl'
    }).when("/saveCash",{
    	templateUrl: resUrl+'wx_api/Module/settlement/views/saveCash.html'+version,
    	controller: 'saveCashCtrl'
    })
    .otherwise({
        redirectTo: '/accountList/0'
    });
    $httpProvider.interceptors.push('timestampMarker');
});

//loading
app.factory('timestampMarker', ["$rootScope", function ($rootScope) {
    var timestampMarker = {
        request: function (config) {
        	console.log($rootScope.uiObj.pageloadingCtrl);
//      	if($rootScope.uiObj.pageloadingCtrl)
//      	{
//      	
//      		$rootScope.uiObj.loading = true;
//          	$rootScope.uiObj.isactive = '';
//          	
//          	
//      	}
            if($rootScope.uiObj.layerloadingCtrl)
            {
            	$rootScope.loadLoyer();
            }
            config.requestTimestamp = new Date().getTime();
            return config;
        },
        response: function (response) {
            response.config.responseTimestamp = new Date().getTime();
            return response;
            
        }
    };
    return timestampMarker;
}]);

//自定义过滤器--时间

app.filter('chatDate',function(){
	return function(input){
		//input就是我们传入的字符串
		if(input)
		{
			input=input.replace(/-/, "/").replace(/-/, "/");
			var date1=new Date(input);  //开始时间
			var date2=new Date();    //结束时间
			var date3=date2.getTime()-date1.getTime()  //时间差的毫秒数
			 
			
			//计算出相差天数
			var days=Math.floor(date3/(24*3600*1000))
			 
			//计算出小时数
			
			var leave1=date3%(24*3600*1000)    //计算天数后剩余的毫秒数
			var hours=Math.floor(leave1/(3600*1000))
			//计算相差分钟数
			var leave2=leave1%(3600*1000)        //计算小时数后剩余的毫秒数
			var minutes=Math.floor(leave2/(60*1000)) 
//			alert(" 相差 "+days+"天 "+hours+"小时 "+minutes+" 分钟"+seconds+" 秒")
			var myDate = new Date(input);
			var result='';
			if(days==0)
			{
				if(hours==0)
				{
					if(minutes==0)
					{
						minutes=1;
					}
					result=minutes+'分钟前';
				}
				else
				{
					result=hours+'小时前';
				}
			}
			else
			{
				result=days+'天前';
			}
			
			return result.toString();
			
		}
	}
})
//限制点赞显示人数
app.filter('praiseFilter',function(){
	return function(input,limit){
		if(input.length>limit)
		{
			input.splice(limit,input.length-limit);
		}
		return input;
	}
})
//解析html
app.filter(  
    'to_trusted', ['$sce', function ($sce) { 
        return function (text) {  
        	
            return $sce.trustAsHtml(text);  
        }  
    }]  
)  